Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 30: Creating Program Scripts

../ch30/30fig01.gif
Figure 30.1

A moving red sphere and a custom interpolator.

30fig01.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
    children [
        Background {
            skyColor    [ 1.0 0.0 0.8,  0.5 0.0 0.8,  0.0 0.0 0.8 ]
            skyAngle    [ 1.309, 1.571 ]
            groundColor [ 0.0 0.0 0.1,  0.0 0.1 0.3,  0.3 0.3 0.6 ]
            groundAngle [ 1.309, 1.571 ]
        },
    # Floor
        Shape {
            appearance Appearance {
                material Material { }
            }
            geometry Box { size 2.0 0.01 0.5 }
        },
    # Animating red ball
        Transform {
            translation 0.0 1.1 0.0
            children DEF BallTransform Transform {
                children Shape {
                    appearance Appearance {
                        material Material {
                            diffuseColor 1.0 0.3 0.3
                        }
                    }
                    geometry Sphere { radius 0.1 }
                }
            }
        },
    # Animation clock
        DEF Clock TimeSensor {
            cycleInterval 4.0
            loop TRUE
        },
    # Script
        DEF Mover Script {
            url "move1.js"
            eventIn  SFFloat set_fraction
            eventOut SFVec3f value_changed
        }
    ]
}
ROUTE Clock.fraction_changed TO Mover.set_fraction
ROUTE Mover.value_changed    TO BallTransform.set_translation